<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<div id="app">
			<person1></person1>
			<person2></person2>
		</div>
		
		<!-- js最后引入-->
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			let bus =new Vue;
			var app = new Vue({
				el: '#app',
				data: {
					

				},
				components:{
					'person1': {
						data: function(){
							return {
								message: 'hello person2'
							};
						},
						template: '<div><h2>{{message}}</h2><button @click="songli">送礼</button></div>',
						mounted: function(){
							//监听
							bus.$on('changeEvents',function(){
								console.log('person1收到了');
							});
						},
						methods:{
								
							songli:function(){
								bus.$emit('jieshou','iphone')
							}
						}
					},
					'person2': {
						data: function(){
							return {
								list: ['哈哈','呵呵','嘻嘻']
							};
						},
						template: `<ul>
						<li @click="getContent" v-for="item in list">{{item}}</li>
						</ul>
						`,
						methods:{
							getContent:function(){
								bus.$emit('changeEvents')
							}
						},
						mounted:function(){
							bus.$on('jieshou',function(val){
								console.log("收到了 "+ val)
							});
						}
					},
					
				}
				
			




			})
		</script>
		<!-- 高亮js -->
	</body>
</html>
